  var mobile_link=document.getElementsByTagName('link')[0];
  var mobile_sUserAgent = navigator.userAgent.toLowerCase();
  var mobile_bIsIpad = mobile_sUserAgent.match(/ipad/i) == "ipad";
  var mobile_bIsIphoneOs = mobile_sUserAgent.match(/iphone os/i) == "iphone os";
  var mobile_bIsMidp = mobile_sUserAgent.match(/midp/i) == "midp";
  var mobile_bIsUc7 = mobile_sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
  var mobile_bIsUc = mobile_sUserAgent.match(/ucweb/i) == "ucweb";
  var mobile_bIsAndroid = mobile_sUserAgent.match(/android/i) == "android";
  var mobile_bIsCE = mobile_sUserAgent.match(/windows ce/i) == "windows ce";
  var mobile_bIsWM = mobile_sUserAgent.match(/windows mobile/i) == "windows mobile";
  var is_mobile = false;
  if (mobile_bIsIpad || mobile_bIsIphoneOs || mobile_bIsMidp || mobile_bIsUc7 || mobile_bIsUc || mobile_bIsAndroid || mobile_bIsCE || mobile_bIsWM) {
      //手机移动端访问地址
      is_mobile = true;
  }

  var ajax = function(obj){

    var that = this;

    if(is_mobile){
      var index = layer.open({shadeClose: false,type: 2});
    }else{
      var index = layer.load(1, {
        shade: [0.5,'#111'] //0.1透明度的白色背景
      });
    }

    var url = obj.url ? obj.url : '';
    var data = obj.data ? obj.data : '';
    var type = obj.type ? obj.type : ''; // 请求方式
    var async = obj.async ? obj.async : true; // 是否异步
    var dataType = obj.dataType ? obj.dataType : ''; // 请求类型

    var header = obj.header ? obj.header : {Accept: "application/json; charset=utf-8"};
    var responseType = obj.responseType ? obj.responseType : '';
    var success = obj.success ? obj.success : '';
    var fail = obj.fail ? obj.fail : '';
    var error = obj.error ? obj.error : '';
    var complete = obj.complete ? obj.complete : '' ;

    var objs = {};
    if(url){
      objs.url = url;
    }

    if (data) {
      objs.data = data;
    }

    if (async) {
      objs.async = async;
    }

    if (header) {
      objs.headers = header;
    }

    if (type) {
      objs.type = type;
    }

    if (dataType) {
      objs.dataType = dataType;
    }

    if (responseType) {
      objs.responseType = responseType;
    }

    objs.success = function (res) {
      if(res.err == 1 || res.err == 2){
        msgtext(res.err,res.msg);
      }else{
        success ? success(res) : '';
        layer.close(index);
      }
    }

    objs.fail = function (res) {
      fail ? fail(res) : '';
      layer.close(index);
    }

    objs.complete = function (res) {
      complete ? complete(res) : '';
      layer.close(index);
    }

    objs.error = function (res) {
      error ? error(res) : '';
      layer.close(index);
    }

    $.ajax(objs);
  };

  var msgtext = function(text,is = 1,functions = false,functionsb = false){
    if(is == 1){
        if(is_mobile){
          layer.open({
            content: text
            ,skin: 'msg'
            ,time: 2 
          });
        }else{
          layer.msg(text, {icon: 1});
        }
    }else if(is == 2){
        if(is_mobile){
          layer.open({
            content: text,
            btn: ["关闭"],
            yes: function(index){
              layer.close(index);
              if(functions){
                functions();
              }
            }
          });
        }else{
          layer.confirm(
            text, 
            {btn: ["关闭"]},
            function(index){
              layer.close(index);
              if(functions){
                functions();
              }
            });
        }
    }else{
        if(is_mobile){
          layer.open({
            content: text,
            btn: ['确认','关闭'],
            yes: function(index){
              layer.close(index);
              if(functions){
                functions();
              }
            },
            no: function(index){
              layer.close(index);
              if(functionsb){
                functionsb();
              }
            }
          });
        }else{
          layer.confirm(
            text, 
            {btn: ['确认','关闭']}, 
            function(index){
              layer.close(index);
              if(functions){
                functions();
              }
            },
            function(index){
              layer.close(index);
              if(functionsb){
                functionsb();
              }
            });
        }
    }
  }
